/// Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.VSPowerToys.Common.TaskManager
{

    /// <summary>
    /// Event argument object for Task Completed event. Contains
    /// information about task results
    /// </summary>
    public class TaskCompletedEventArgs : EventArgs
    {
        #region Private Members

		[NonSerialized]
        private Task ownerTask;
        private bool isSuccess;

        private TaskException exception;

        #endregion

        /// <summary>
        /// Task that the event raised for
        /// </summary>
        public Task OwnerTask
        {
            get
            {
                return this.ownerTask;
            }
        }

        /// <summary>
        /// Returns true if task finished successfully
        /// </summary>
        public bool IsSuccess
        {
            get
            {
                return this.isSuccess;
            }
        }

        /// <summary>
        /// If IsSuccess is false, this will contain the exception
        /// raised when task failed
        /// </summary>
        public TaskException ExceptionRaised
        {
            get
            {
                return this.exception;
            }
        }

        /// <summary>
        /// Creates a new event argument object, task is assumed to be
        /// successfully completed.
        /// </summary>
        /// <param name="task"></param>
        public TaskCompletedEventArgs(Task task) : this(task, true, null)
        {

        }

        /// <summary>
        /// Creates a new event argument object.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="isSuccess"></param>
        /// <param name="exception"></param>
        public TaskCompletedEventArgs(Task task, bool isSuccess, TaskException exception)
        {
            this.ownerTask = task;
            this.isSuccess = isSuccess;
            this.exception = exception;
        }
    }


	/// <summary>
	/// An event arguments class for events raised from TaskManager
	/// </summary>
	public class TaskEventArgs : EventArgs
	{
		[NonSerialized]
		private Task task;

		public Task Task
		{
			get { return this.task; }
			set { this.task = value; }
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="task">Task that owns the event</param>
		public TaskEventArgs(Task currentTask)
		{
			this.task = currentTask;
		}
	}

	/// <summary>
	/// An event arguments class for TaskProgress events
	/// </summary>
	public class TaskProgressEventArgs : EventArgs
	{
		[NonSerialized]
		private Task currentTask;

		public Task CurrentTask
		{
			get { return this.currentTask; }
			set { this.currentTask = value; }
		}


		private int currentProgress;

		public int CurrentProgress
		{
			get { return this.currentProgress; }
			set { this.currentProgress = value; }
		}

		private int maxProgressValue;

		public int MaximumProgressValue
		{
			get { return this.maxProgressValue; }
			set { this.maxProgressValue = value; }
		}

		/// <summary>
		/// Constructor for the event args
		/// </summary>
		/// <param name="task">The task being executed</param>
		/// <param name="current">Current value of the progress</param>
		/// <param name="max">Maximum possible value for the progress</param>
		public TaskProgressEventArgs(Task task, int current, int max)
		{
			this.currentTask = task;
			this.currentProgress = current;
			this.maxProgressValue = max;
		}
	}

	/// <summary>
	/// An event arguments class for the TaskAborted event
	/// </summary>
	/// <param name="ex">TaskException that caused the abort. This object contains
	/// owner task information as well.</param>
	public class TaskAbortedEventArgs : EventArgs
	{
		private TaskException taskException;

		public TaskException TaskException
		{
			get { return this.taskException; }
			set { this.taskException = value; }
		}

		public TaskAbortedEventArgs(TaskException exception)
		{
			this.taskException = exception;
		}
	}

    /// <summary>
    /// An event argument class for messages sent from Tasks
    /// </summary>
    public class TaskMessageAvailableEventArgs : TaskEventArgs
    {
        private string message;

        /// <summary>
        /// Message sent from task
        /// </summary>
        public string Message
        {
            get { return this.message; }
            set { this.message = value; }
        }

        /// <summary>
        /// Creates a new event arguments object
        /// </summary>
        /// <param name="task">Task that is sending the message</param>
        /// <param name="message">Text of the message</param>
        public TaskMessageAvailableEventArgs(Task task, string message) :
            base(task)
        {
            this.message = message;
        }
    }
}
